package moe.oil.db.repo;


import moe.oil.db.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Optional;

public interface UserRepo extends PagingAndSortingRepository<User, Long> {

    /**
     * 查询指定用户
     *
     * @param username
     * @return
     */
    Optional<User> findByUsername(String username);

    /**
     * 查询全部
     *
     * @param pageable
     * @return
     */
    Page<User> findAll(Pageable pageable);

    /**
     * 根据ID查询用户
     *
     * @param id
     * @return
     */
    Optional<User> findByUserId(Long id);

    /**
     * 查询指定Email的用户
     * 可能抛出的异常：IllegalArgumentException: Invalid pageable: null
     *
     * @param email
     * @return
     */
    Optional<User> findByEmail(String email);

    /**
     * 登陆
     *
     * @param id
     */
    @Modifying
    int deleteByUserId(Long id);
}
